package com.ruoyi.project.sdi.sdiImage.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.sdi.sdiImage.domain.SdiImage;
import com.ruoyi.project.sdi.sdiImage.service.ISdiImageService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 影像表Controller
 *
 * @author 关晓强
 * @date 2020-03-16
 */
@Controller
@RequestMapping("/sdi/sdiImage")
public class SdiImageController extends BaseController
{
    private String prefix = "sdi/sdiImage";

    @Autowired
    private ISdiImageService sdiImageService;

    @RequiresPermissions("sdi:sdiImage:view")
    @GetMapping()
    public String sdiImage()
    {
        return prefix + "/sdiImage";
    }

    /**
     * 查询影像表列表
     */
    @RequiresPermissions("sdi:sdiImage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SdiImage sdiImage)
    {
        startPage();
        List<SdiImage> list = sdiImageService.list(new QueryWrapper<>(sdiImage));
        return getDataTable(list);
    }

    /**
     * 导出影像表列表
     */
    @RequiresPermissions("sdi:sdiImage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SdiImage sdiImage)
    {
        List<SdiImage> list = sdiImageService.list(new QueryWrapper<>(sdiImage));
        ExcelUtil<SdiImage> util = new ExcelUtil<SdiImage>(SdiImage.class);
        return util.exportExcel(list, "sdiImage");
    }

    /**
     * 新增影像表
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存影像表
     */
    @RequiresPermissions("sdi:sdiImage:add")
    @Log(title = "影像表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SdiImage sdiImage)
    {
        return toAjax(sdiImageService.saveOrUpdate(sdiImage));
    }

    /**
     * 修改影像表
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SdiImage sdiImage = sdiImageService.getById(id);
        mmap.put("sdiImage", sdiImage);
        return prefix + "/edit";
    }

    /**
     * 修改保存影像表
     */
    @RequiresPermissions("sdi:sdiImage:edit")
    @Log(title = "影像表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SdiImage sdiImage)
    {
        return toAjax(sdiImageService.saveOrUpdate(sdiImage));
    }

    /**
     * 删除影像表
     */
    @RequiresPermissions("sdi:sdiImage:remove")
    @Log(title = "影像表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sdiImageService.removeByIds(Arrays.asList(ids.split(","))));
    }
}
